﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Text.RegularExpressions;
using System.Data;
using System.Data.Common;
using System.Globalization;
using T4Ui.Utility;

namespace T4Ui.dal
{
    public class OracleDbBase:DbBase
    {
       

      
        public OracleDbBase():
            base()
        {

        }
          //string FKSql = @"select cu.* from user_cons_columns cu, user_constraints au where cu.constraint_name = au.constraint_name and au.constraint_type = 'P' and au.table_name ={0}table_name";


          //string TABLE_SQL = @"select * from user_tables ";

          //string COLUMN_SQL = @"select Table_Name , COLUMN_NAME ColumnName ,DATA_TYPE DataType, DATA_LENGTH MaxLength  from user_tab_columns where Table_Name={0}Table_Name";

        //string PriSql = "";

        public override string GetTableSql()
        {
            return @"select * from user_tables ";
        }

        public override DbCommand GetColumnCmd(Table tbl)
        {
            DbCommand cmd=dal.GetSqlStringCommond(@"select Table_Name , COLUMN_NAME ColumnName ,DATA_TYPE DataType, DATA_LENGTH MaxLength  from user_tab_columns where Table_Name=:Table_Name");
            // cmd.Parameters.AddWithValue(":Table_Name", tbl.Name);
            dal.AddInParameter(cmd, ":Table_Name", DbType.String, tbl.Name);
            return cmd;
        }

        public override DbCommand GetFKCommand(string tableName)
        {
            throw new NotImplementedException();
        }

        public override DbCommand GetPKCommand(string table)
        {
            string sql = @"select cu.* from user_cons_columns cu, user_constraints au where cu.constraint_name = au.constraint_name and au.constraint_type = 'P' and au.table_name =:tableName";
           
            var cmd =dal.GetSqlStringCommond(sql);
            //cmd.Parameters.AddWithValue(":tableName", table);
            dal.AddInParameter(cmd,":tableName", DbType.String, table);
            return cmd;
        }
    }
}
